import { Good } from '@/modules/businessModule/good/assets/good.entity';
import { Platform } from '@/modules/businessModule/platform/assets/platform.entity';
import { Spec } from '@/modules/businessModule/spec/assets/spec.entity';
import { SpecsType } from '@/modules/businessModule/specsType/assets/specsType.entity';
import { ApiProperty } from '@nestjs/swagger';
import {
  Column,
  Entity,
  JoinColumn,
  JoinTable,
  ManyToMany,
  ManyToOne,
  OneToMany,
  PrimaryGeneratedColumn,
} from 'typeorm';

@Entity()
export class Product {
  @PrimaryGeneratedColumn()
  id: number;

  @Column()
  @ApiProperty({ description: '规格名称' })
  productName: string;

  @Column({ type: 'text', nullable: true })
  @ApiProperty({ description: '规格说明' })
  productAtention?: string;

  @Column({ type: 'float' })
  @ApiProperty({ example: 9.5, type: 'float', description: '规格价格' })
  productPrice: number;

  @Column()
  @ApiProperty({ description: '规格图片' })
  productImg: string;

  @Column({ type: 'bigint' })
  @ApiProperty({ type: 'bigint', description: '时长' })
  productTime: number;

  @Column()
  @ApiProperty({ description: '位数' })
  productNum: number;

  @ManyToMany(() => Spec)
  @ApiProperty({ description: '规格属性', type: () => Spec })
  @JoinTable({ name: 'product_spec' })
  specs: Spec[];

  @ManyToMany(() => SpecsType)
  @ApiProperty({ description: '规格类型属性', type: () => SpecsType })
  @JoinTable({ name: 'product_specstype' })
  specsType: SpecsType[];

  @ManyToOne(() => Platform, (platform) => platform.product)
  @ApiProperty({ description: '商品', type: () => Platform })
  @JoinColumn()
  platform: Platform;

  @OneToMany(() => Good, (good) => good.product)
  @ApiProperty({ description: '物品', type: () => Good })
  good: Good[];
}
